package com.lagou.rpc;

import com.lagou.handler.UserClientHandler;

import java.util.Map;
import java.util.Random;

/**
 * @author ascetic
 * @version 1.0
 * @ClassName RandomFindLink
 * @Description TODO
 * @date 2020-07-03 22:09
 */
public class RandomFindLink implements FindLinkHandler{


    @Override
    public String findLink(Map<String, UserClientHandler> tcpLink) {

        int rn = getRandomInt(tcpLink.size());
        int i = 0;
        for (String key : tcpLink.keySet()) {
            if(i==rn){
                return key;
            }
            i++;
        }
        return null;
    }


    public static int getRandomInt(int max) {
        Random random =new Random();
        return random.nextInt(max);
    }
}